package com.erik.lin.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by Erik on 2017/5/21.
 */
@Controller
@RequestMapping("/cookie")
public class CookieController {

    @RequestMapping(value = "/add", method = RequestMethod.GET)
    public @ResponseBody
    Map<String, Object> addCookie(HttpServletRequest request, HttpServletResponse response) {
        Cookie cookie = new Cookie("user_token", "lin");
        cookie.setDomain("localhost");
        cookie.setPath("/");
        response.addCookie(cookie);
        Map<String, Object> rs = new HashMap<String, Object>();
        rs.put("success", true);
        return rs;
    }
}
